﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebApplication6.DAL.DataSetUserTableAdapters;

namespace WebApplication6.manage
{
    public partial class password : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            string password = txtpassword.Text;

            string password2 = txtpassword2.Text;

            t_userTableAdapter adapter = new t_userTableAdapter();

            string username = Convert.ToString(Session["username"]);

            var userrows = adapter.GetDataByusername(username);

            if (userrows.Count() > 0)
            {
                var user = userrows.Single();
                if (user.password != password)
                {
                    Response.Write("<script language=javascript>alert('原密码不正确，操作失败');window.location.href='password.aspx';</script>");

                }
                else
                {

                    adapter.Updatepassword(password2, user.username);

                    Response.Write("<script language=javascript>alert('操作成功');window.location.href='password.aspx';</script>");

                }

            }
            else
            {

                Response.Write("<script language=javascript>alert('登录超时,请重新登录');window.location.href='password.aspx';</script>");
            }

        }
    }
}
